package com.fc.happyteam.common.convert;


import com.fc.happyteam.dto.BoatDto;
import com.fc.happyteam.entity.BoatEntity;
import com.fc.happyteam.utils.StringUtils;

/**
 * Created by futurecreative on 2017/8/1.
 */
public class BoatConverter extends SkuConverter {

    @Override
    public void convertFromDto(Object source, Object target) {
        super.convertFromDto(source, target);
        BoatDto boatDto = (BoatDto) source;
        if (boatDto.getLocations() != null && boatDto.getLocations().length > 0) {
            ((BoatEntity) target).setLocation(StringUtils.mkString(boatDto.getLocations(), "", "", ","));
        }
        if (boatDto.getEquips() != null && boatDto.getEquips().length > 0) {
            ((BoatEntity) target).setEquip(StringUtils.mkString(boatDto.getEquips(), "", "", ","));
        }
    }

    @Override
    public void convertToDto(Object source, Object target) {
        super.convertToDto(source, target);
        BoatEntity boatEntity = (BoatEntity) source;
        if (!StringUtils.isEmpty(boatEntity.getLocation())) {
            ((BoatDto) target).setLocations(boatEntity.getLocation().split(","));
        }
        if (!StringUtils.isEmpty(boatEntity.getEquip())) {
            ((BoatDto) target).setEquips(boatEntity.getEquip().split(","));
        }
    }
}
